﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Principal;

namespace proyectoENS
{
   class Users : IIdentity
        {
            private bool isAuthenticated = false;
            private string name, authenticationType;
            private int idUsu;
            // Implement private variables for custom properties
            private string nombres, apellidos;
            // Allow the creation of an empty object
            public Users()
            {
                this.name = String.Empty;
                this.isAuthenticated = false;
                this.authenticationType = "None";
                this.nombres = String.Empty;
                this.apellidos = String.Empty;

            }


            public Users(bool isLogin, string newAuthenticationType,
            string newNombres,
            string newApellidos, int idUsu)
            {

                // Create a unique username by concatenating first and last name
                this.name = newNombres +", " + newApellidos;
                this.isAuthenticated = isLogin;
                this.authenticationType = newAuthenticationType;
                this.nombres = newNombres;
                this.apellidos = newApellidos;
                this.idUsu = idUsu;

            }
            // Implement public read-only interfaces for standard properties
            public bool IsAuthenticated
            { get { return this.isAuthenticated; } }
            public string Name
            { get { return this.name; } }
            public string AuthenticationType
            { get { return this.authenticationType; } }

            public string FirstName
            { get { return this.nombres; } }
            public string LastName
            { get { return this.apellidos; } }
            
            public int IdUsu
            { get { return this.idUsu; } }


        }
        class CustomPrincipal : IPrincipal
        {
            private IIdentity _identity;
            private string[] _roles;
            public CustomPrincipal(IIdentity identity, string[] roles)
            {
                _identity = identity;
                _roles = new string[roles.Length];
                roles.CopyTo(_roles, 0);
                Array.Sort(_roles);
            }

            public IIdentity Identity
            { get { return _identity; } }

            public bool IsInRole(string role)
            { return Array.BinarySearch(_roles, role) >= 0 ? true : false; }
        }
    }

